package com.briup.sms.web.controller;

import com.briup.sms.entity.User;
import com.briup.sms.service.UserService;
import com.briup.sms.utils.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author :xuyang
 * @DateTime:2024/1/10 23:36
 * @Version :v1.0.0
 * ClassName:UserController
 * Package  :com.briup.sms.web.controller
 * Description:TODO
 */
@RestController
@RequestMapping("/user")
@Api(tags = "会员管理")
@CrossOrigin
public class UserController {

    @Autowired
    UserService service;

    @GetMapping("/findUserInfo")
    @ApiOperation("查询所有会员信息")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "username", value = "用户名"),
                    @ApiImplicitParam(name = "pageSize", value = "分页每页数据条数", required = true),
                    @ApiImplicitParam(name = "pageNum", value = "页码", required = true)
            }
    )
    public Result findUserInfo(String username, Integer pageSize, Integer pageNum) {
        PageInfo<User> users = service.findUserInfo(username, pageSize, pageNum);
        return Result.success(users);
    }

    @PutMapping("/user/disable/{id}")
    @ApiOperation("禁用会员")
    public Result disable(@PathVariable Integer id) {
        service.updateLock(id);
        return Result.success();
    }

    @PutMapping("/user/enable/{id}")
    @ApiOperation("开启会员")
    public Result enable(@PathVariable Integer id) {
        service.updateStart(id);
        return Result.success();
    }

}
